import { join } from 'path'
import { MiddlewareConsumer, Module } from '@nestjs/common'
import { JwtModule } from '@nestjs/jwt'
import { JwtMiddleware } from './core/jwt.middleware'
import { AdminController } from './controllers/admin.controller'
import { AdminService } from './services/admin.service'
import { AzureAppController } from './controllers/azure-app.controller'
import { AzureAppOAuthController } from './controllers/azure-app-oauth.controller'
import { AzureAppOAuthService } from './services/azure-app-oauth.service'
import { AzureAppService } from './services/azure-app.service'
import { AzureAppRenewController } from './controllers/azure-app-renew.controller'
import { AzureAppRenewService } from './services/azure-app-renew.service'
import { ServeStaticModule } from '@nestjs/serve-static'

@Module({
  imports: [
    ServeStaticModule.forRoot({
      rootPath: join(__dirname, '../', 'client'),
    }),
    JwtModule.register({
      secret: process.env.Jwt_Secret,
      signOptions: { expiresIn: '720h' }
    })
  ],
  controllers: [
    AdminController, AzureAppController, AzureAppOAuthController, AzureAppRenewController
  ],
  providers: [
    AdminService, AzureAppService, AzureAppOAuthService, AzureAppRenewService
  ],
})
export class AppModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(JwtMiddleware)
      .forRoutes('*')
  }
}
